package com.tgy.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @Author: tgy
 * @Date: 12/1/20 3:46 PM
 */
public class FutureTaskDemo {


    public static void main(String[] args) {

        FutureTask<String> futureTask = new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {

                TimeUnit.SECONDS.sleep(5);
                return "哈哈";
            }
        });


        new Thread(futureTask,"t1").start();

        try {

            System.out.println(futureTask.get());
        } catch (Exception e) {

            e.printStackTrace();
        }

        Thread.interrupted();

    }

}
